package com.lf.cloud.fm.controller.rec;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.plugin.activerecord.Page;
import com.lf.cloud.comm.controller.BaseController;
import com.lf.cloud.comm.dao.BlogContentDao;
import com.lf.cloud.comm.dao.BlogTagsDao;
import com.lf.cloud.comm.dao.EnumsDao;
import com.lf.cloud.comm.modal.dto.ResponeObj;
import com.lf.cloud.comm.modal.dto.TagsDto;
import com.lf.cloud.comm.modal.pojo.BlogContent;
import com.lf.cloud.comm.modal.pojo.BlogTags;
import com.lf.cloud.comm.modal.pojo.Enums;
import com.lf.cloud.comm.webutils.BigNumber;
import com.lf.cloud.comm.webutils.CommMethod;
import com.lf.cloud.fm.business.BlogContentBusiness;
import com.lf.conf.MyConstants;

public class IndexController extends BaseController {
	
	
	public void index(){
		render("index.jsp");
	}
	
	
	
	public void index1(){
		String geetEnumsVal = EnumsDao.me.geetEnumsVal("_rec_gallery_page_size");
		Page<BlogContent> blogContentPage = BlogContentBusiness.bus.getBlogContentPage(1, Integer.parseInt(geetEnumsVal), null);
		List<Enums> pageSize = BlogContentBusiness.bus.getPageSize(blogContentPage.getPageSize());
		setAttr("pageSize", pageSize);
		setAttr("gallery", blogContentPage);
		render("rec_index_content.jsp");
	}

	
	
	
	public void initdata(){
		
		BlogContentBusiness.bus.inintData();
		ResponeObj obj = new ResponeObj();
		obj.setCode(MyConstants.CODE_SUCCESS);
		super.success(obj);
	}
	
	
	public void initTags(){
		BlogContentBusiness.bus.initTags();
		ResponeObj obj = new ResponeObj();
		obj.setCode(MyConstants.CODE_SUCCESS);
		super.success(obj);
	}
	
	
	public void toGallery(){
		String geetEnumsVal = EnumsDao.me.geetEnumsVal("_rec_gallery_page_size");
		Page<BlogContent> blogContentPage = BlogContentBusiness.bus.getBlogContentPage(1, Integer.parseInt(geetEnumsVal), null);
		List<Enums> pageSize = BlogContentBusiness.bus.getPageSize(blogContentPage.getPageSize());
		setAttr("pageSize", pageSize);
		setAttr("gallery", blogContentPage);
		List<TagsDto> tagsList = BlogContentBusiness.bus.getTagsList();
		setAttr("tagsList", tagsList);
		render("gallery/rec_index.jsp");
	}
	
	
	
	public void selectTags(){
		
		String geetEnumsVal = EnumsDao.me.geetEnumsVal("_rec_gallery_page_size");
		String tagNo = getPara("tagNo");
		BlogTags obj = BlogTagsDao.me.geetBlogTagByTagNo(tagNo);
		String tagName = obj.getTagName();
		
		
		Page<BlogContent> blogContentPage = BlogContentBusiness.bus.getBlogContentPage(1, Integer.parseInt(geetEnumsVal), tagName);
		setAttr("gallery", blogContentPage);
		List<TagsDto> tagsList = BlogContentBusiness.bus.getTagsList();
		setAttr("tagName", tagName);
		setAttr("tagsList", tagsList);
		render("gallery/rec_index.jsp");
	}
	
	
	
	 /**  
	* @Title: getGalleryPage  
	* @Description: Ajax 图库分页
	* @returnType void      
	* @author LiuFei
	* @date 下午10:17:41
	* @throws  
	*/  
	    
	public void getGalleryPage(){
		Map<String, Object> map = CommMethod.getMap();
		String pageNumStr = getPara("page");
		//String pageSizeStr = getPara("pageSizeStr");
		//String tagNo = getPara("tagNo");
		String tagName = getPara("tagName");
		String pageSizeStr = EnumsDao.me.geetEnumsVal("_rec_gallery_page_size");
		Page<BlogContent> blogContentPage = BlogContentBusiness.bus.getBlogContentPage(Integer.parseInt(pageNumStr), Integer.parseInt(pageSizeStr), tagName);
		map.put("gallery", blogContentPage);
		super.success(map);
		
//		String blogContentPageHtml = BlogContentBusiness.bus.getBlogContentPageHtml(Integer.parseInt(pageNumStr), Integer.parseInt(pageSizeStr), tagNo);
//		
//		super.success(blogContentPageHtml);
	}
	
	
	
	  
	/**  
	* @Title: getGalleryContent  
	* @Description: TODO(这里用一句话描述这个方法的作用)  
	* @param 
	* @return void
	* @author lxliufei
	* @date 下午2:14:15
	* @throws  
	*/  
	public void getGalleryContent(){
		String id = getPara("serialId");
		Map<String, Object> map = CommMethod.getMap();
		if(StringUtils.isNotEmpty(id)){
			BlogContent obj = BlogContentBusiness.bus.getGalleryContent(id);
			setAttr("gallery", obj);
		}
		render("rec_content.jsp");
	}
	
	
	
	
	
	
}
